package com.xuexiang.xuidemo.slice.status;

import com.xuexiang.xui_lib.component.TitleBarLayout;
import com.xuexiang.xui_lib.component.status.CustomStateOptions;
import com.xuexiang.xui_lib.component.status.StatefulLayout;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.slice.BaseAbilitySlice;
import com.xuexiang.xuidemo.util.ToastUtil;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;

/**
 * 自定义模板StatusLayout
 */
public class StatefulLayoutSlice extends BaseAbilitySlice {

    private Component.ClickedListener clickedListener = component -> ToastUtil.showToast(getContext(), "点击重试按钮!");

    @Override
    protected int getTitleBarId() {
        return ResourceTable.Id_title_bar;
    }

    @Override
    protected int getUIContentLayoutId() {
        return ResourceTable.Layout_ability_slice_stateful;
    }

    @Override
    protected void initComponents() {
        StatefulLayout statefulLayout = (StatefulLayout) findComponentById(ResourceTable.Id_status_layout);


        findComponentById(ResourceTable.Id_content_btn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statefulLayout.showContent();
            }
        });
        findComponentById(ResourceTable.Id_loading_btn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statefulLayout.showLoading();
            }
        });
        findComponentById(ResourceTable.Id_empty_btn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statefulLayout.showEmpty();
            }
        });
        findComponentById(ResourceTable.Id_error_btn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statefulLayout.showError(clickedListener);
            }
        });
        findComponentById(ResourceTable.Id_offline_btn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statefulLayout.showOffline(clickedListener);
            }
        });
        findComponentById(ResourceTable.Id_locationOff_btn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statefulLayout.showLocationOff(clickedListener);
            }
        });
        findComponentById(ResourceTable.Id_loading_btn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statefulLayout.showLoading();
            }
        });
        findComponentById(ResourceTable.Id_custom_btn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                statefulLayout.showCustom(new CustomStateOptions()
                    .image(ResourceTable.Media_bluetooth_disabled)
                    .message("请打开蓝牙")
                    .buttonText("设置")
                    .buttonClickListener(clickedListener)
                );
            }
        });
    }

}
